package com.itheima.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
public class RabbitmqListener {
    @RabbitListener(queues = "routing_queue_springboot2")
    public void rabbitmqListener(Message message, Channel channel) throws IOException, InterruptedException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        Thread.sleep(1000);
        try {
            System.out.println(new String(message.getBody()));
            System.out.println("逻辑处理");
            //int i=8/0;
            channel.basicAck(deliveryTag, true);
        } catch (Exception e) {
            // e.printStackTrace();
            channel.basicNack(deliveryTag, true, true);
        }
    }
    @RabbitListener(queues = "queueDlx")
    public void rabbitmqListenertwo(Message message, Channel channel) throws IOException, InterruptedException {
        System.out.println(new String(message.getBody()));
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);
    }
}
